package com.br.apurn.model.service;

import java.util.List;

import com.br.apurn.model.dao.DAOException;
import com.br.apurn.model.dao.MapsDAO;
import com.br.apurn.model.dao.MapsDAOImpl;

import com.br.apurn.model.Local;

public class MapsServiceImpl implements MapsService {
	
	private static MapsService singleton = null;
	
	private MapsDAO mapsDao;
	
	private MapsServiceImpl() {
		mapsDao = new MapsDAOImpl();
	}
	
	public static MapsService getInstance() {
		if (singleton == null) {
			singleton = new MapsServiceImpl();
		}
		return singleton;
	}

	@Override
	public void save(Local l) {
			try {
				mapsDao.addEntity(l);
			} catch (DAOException e) {
				e.printStackTrace();
			}	
	}

	@Override
	public Local getById(Integer id) {
		try {
			return mapsDao.findById(id);
		} catch (DAOException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public void delete(Integer id) {
		try {
			mapsDao.removeEntity(this.getById(id), id);
		} catch (DAOException e) {
			e.printStackTrace();
		}
		
	}
	
	@Override
	public List<Local> listAllMaps() {
		List<Local> l = null;
		try {
			l = mapsDao.findAll("Local");
		} catch (DAOException e) {
			e.printStackTrace();
		}
		return l;
	}


}
